import code,sys


def keyboard(banner=None):
    try:
        raise None
    except:
        frame = sys.exc_info()[2].tb_frame.f_back

    namespace = frame.f_globals.copy()
    namespace.update(frame.f_locals)

    code.interact(banner=banner, local=namespace)


def func():
    print("START")
    a = 10
    keyboard()
    print("END")


func()